
/*******************************************************************************									   
// program: 		GenderSegVET_WaldTest.do
// task:    		Calculation of WaldTest
// project: 		VET Gender Segregation 
// author:  		Benita Combet
// date:    		8 Oct 2024		
// programmes: 		conjoint, fre														   
********************************************************************************/



clear

ssc install conjoint
ssc install fre


/*

* Data import
import excel "/Users/benita/Documents/1-Research/1-Current/GenderSeg/GenderSeg9_SkillsVET/Berechnungen/20240228_ICTdata.xlsx", sheet("Sheet 1") firstrow


* Operationalization

fre Choice Conventional Creativity Entrepreneurial Familyfriendly ICT_Reliance Meaningful_Work Salary_Expectations Social_Interactions

encode ResponseId, gen(id)
encode Choice_Number, gen(choicenr)
encode Profile, gen(profile)

clonevar choice = Choice
encode Conventional, gen(ch_convent)
encode Creativity, gen(ch_creativity)
encode Entrepreneurial, gen(ch_entrepre)
encode Familyfriendly, gen(ch_family)
encode ICT_Reliance, gen(ch_ICT)
encode Meaningful_Work, gen(ch_meaningful_Work)
encode Salary_Expectations, gen(ch_salary)
encode Social_Interactions, gen(ch_social)
encode var_gen, gen(sex)

recode ch_creativity ch_meaningful ch_ICT ch_salary (2=0) 
recode ch_convent ch_entrepre ch_family ch_social (1=0) (2=1)
label define ch_ 0 "low" 1 "high", modify
label values ch_* ch_
fre ch_*

recode sex (2 = 0)
label define sex 0 "male" 1 "female", modify
label value sex sex
fre sex


*/

* All
conjoint choice ch_ICT ch_social ch_creativity ch_convent ch_entrepre ch_family ch_salary ch_meaningful_Work, estimate(mm) subgroup(sex) id(id)

* Subgroups
conjoint choice ch_ICT ch_social ch_creativity ch_convent ch_entrepre ch_family ch_salary ch_meaningful_Work, estimate(mm) subgroup(sex) id(id)


* Test if results are the same by artificially constraining on subgroups
conjoint choice ch_ICT ch_social ch_creativity ch_convent ch_entrepre ch_family ch_salary ch_meaningful_Work if sex == 0, estimate(mm) id(id)


* Wrapper Program for Wald Test
program bsexpconjoint
    local roweq: roweq e(results)
    local rown: rown e(results)
    local exp
    local i 0
    local eq0
    foreach eq of local roweq {
        if "`eq'"!="`eq0'" {
            if "`eq0'"!="" local exp `exp')
            local exp `exp' (`eq':
        }
        local eq0 "`eq'"
        gettoken n rown : rown
        local ++i
        local exp `exp' `n' = el(e(results),`i',1)
    }
    local exp `exp')
    c_local bsexp `exp'
end


* Wald Test for Men

preserve 

	keep if sex==0
	
local factors ch_ICT ch_social ch_creativity ch_convent ch_entrepre ch_family ch_salary ch_meaningful_Work
conjoint choice `factors', estimate(mm) id(id) 
bsexpconjoint
bootstrap `bsexp', cluster(id) idcluster(newid): ///
    conjoint choice `factors', estimate(mm) id(newid)
	
	
	
dis ((_b[ICT_Reliance:low] + _b[Social_Interactions:high] + _b[Creativity:high] + _b[Conventional:high] + _b[Entrepreneurial:low])/5) - ((_b[Familyfriendly:high] + _b[Salary_Expectations:high] + _b[Meaningful_Work:high]) / 3)

// difference btw averages of 2 dimensions = -0.0351


test ((_b[ICT_Reliance:low] + _b[Social_Interactions:high] + _b[Creativity:high] + _b[Conventional:high] + _b[Entrepreneurial:low])/5) = ((_b[Familyfriendly:high] + _b[Salary_Expectations:high] + _b[Meaningful_Work:high]) / 3)

// chi2(1)  = 79.49
// p > chi2 = 0.0000


restore




* Wald Test for Women

preserve 

	keep if sex==1
	
local factors ch_ICT ch_social ch_creativity ch_convent ch_entrepre ch_family ch_salary ch_meaningful_Work
conjoint choice `factors', estimate(mm) id(id) 
bsexpconjoint
bootstrap `bsexp', cluster(id) idcluster(newid): ///
    conjoint choice `factors', estimate(mm) id(newid)

dis ((_b[ICT_Reliance:low] + _b[Social_Interactions:high] + _b[Creativity:high] + _b[Conventional:high] + _b[Entrepreneurial:low])/5) - ((_b[Familyfriendly:high] + _b[Salary_Expectations:high] + _b[Meaningful_Work:high]) / 3)

// difference btw averages of 2 dimensions = -0.009
	
test ((_b[ICT_Reliance:low] + _b[Social_Interactions:high] + _b[Creativity:high] + _b[Conventional:high] + _b[Entrepreneurial:low])/5) = ((_b[Familyfriendly:high] + _b[Salary_Expectations:high] + _b[Meaningful_Work:high]) / 3)

// chi2(1)  = 5.06
// p > chi2 = 0.0245
	
restore


